package com.lhb.controller;

import com.lhb.dao.Repository.RoleRepository;
import com.lhb.pojo.BaseResp;
import com.lhb.pojo.TbRole;
import com.lhb.pojo.rep.RolePermissionReq;
import com.lhb.service.RoleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author LiangHaiBo
 * @version 1.0
 * @date 2021.10.13 下午 17:01
 */
@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    RoleService roleService;

    @RequiresPermissions(value = {"SYSTEM_ROLE_AUTH"})
    @RequestMapping("/findAll")
    public BaseResp findAll(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit) {
        return roleService.findAll(page, limit);
    }


    @RequestMapping("/insertRole")
    public BaseResp insertRole(@RequestBody TbRole tbRole) {
        System.out.println(tbRole);
        return roleService.insertRole(tbRole);
    }


    @RequestMapping("/del")
    public void delete(@RequestParam("id") Integer id) {
        roleService.deleteById(id);
    }


    @RequestMapping("/updatePermission")
    public BaseResp updatePermission(@RequestBody RolePermissionReq req) {
        return roleService.updatePermission(req);
    }

    @RequestMapping("/findRoleByUser")
    public BaseResp findRoleByUser(@RequestParam("id") Integer userid) {
        return roleService.findByUser(userid);
    }
}
